#ifndef HLS_M3U8_PARSER_H_
#define HLS_M3U8_PARSER_H_

#include "hls_m3u8_message.h"
#include <cstdint>
#include <map>
#include <functional>

class HlsM3u8Parser
{
public:
                     HlsM3u8Parser();
    void             InitParser();
    int              Parser(const uint8_t * data, int data_length, int & use_length);
    HlsM3U8Message * HlsMessage();
    void             ClearHlsMessage();
    static bool      ProcessStreamInfo(const std::string & raw, HlsM3U8Message::StreamInfo & stream_info);
    static void      SplitField(const std::string & raw, std::map<std::string, std::string> & result, const std::string & split);
    //#EXTM3U
    int ExtM3u(const std::string & prefix, const std::string & line);
    //#EXT-X-TARGETDURATION
    int ExtXTargetDuration(const std::string & prefix, const std::string & line);
    //#EXT-X-VERSION
    int ExtXVersion(const std::string & prefix, const std::string & line);
    //#EXT-X-MEDIA-SEQUENCE
    int ExtXMetaSequence(const std::string & prefix, const std::string & line);
    //#EXT-X-PLAYLIST-TYPE
    int ExtXPlayListType(const std::string & prefix, const std::string & line);
    //#EXTINF
    int ExtInf(const std::string & prefix, const std::string & line);
    //#EXT-X-ENDLIST
    int ExtXEndList(const std::string & prefix, const std::string & line);
    //#EXT-X-STREAM-INF
    int ExtXStreamInf(const std::string & prefix, const std::string & line);
    int ResourceIndex(const std::string & line);
private:
    std::string    m_ext_info;
    HlsM3U8Message m_hls_message{};
    std::map<std::string, std::function<int(const std::string&, const std::string&)>> m_parser_func_map;
};

#endif
